<template>
  <div class="box1">
    <div class="title">
      <p>男女比例</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="sex">
      <div class="man">
        <img src="../../images/man.png" alt="" />
      </div>
      <div class="woman">
        <img src="../../images/woman.png" alt="" />
      </div>
    </div>
    <div class="rate">
      <p>男士58%</p>
      <p>女士42%</p>
    </div>
    <!-- 图表 -->
    <div class="charts" ref="chartsRef"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
const chartsRef = ref();

onMounted(() => {
  const myCharts = echarts.init(chartsRef.value);
  myCharts.setOption({
    xAxis: {
      show: false,
      min: 0,
      max: 100,
      // 轴线设置
      axisLine: {
        show: false,
      },
    },
    yAxis: {
      type: "category",
      show: false, // ✅ 直接隐藏整个 y 轴
    },

    series: [
      {
        type: "bar",
        data: [58],
        barWidth: 20,
        z: 100,
        itemStyle: {
          color: "skyblue",
          borderRadius: 20,
        },
      },
      {
        type: "bar",
        data: [100],
        barWidth: 20,
        // 调整位置
        barGap: "-100%",
        itemStyle: {
          color: "pink",
          borderRadius: 20,
        },
      },
    ],
    grid: {
      left: 50,
      top: 0,
      right: 50,
      bottom: 0,
    },
  });
});
</script>

<style scoped lang="scss">
.box1 {
  margin-top: 10px;
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-lc.png) no-repeat center;
  background-size: 100% 100%;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  color: #ffffff;

  .title {
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    margin-left: 20px;

    p {
      font-size: 22px;
      font-weight: bold;
      color: #ffffff;
    }

    img {
      width: 80px;
      height: auto;
    }
  }

  .sex {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 20px;

    .man,
    .woman {
      width: 120px;
      height: 180px;
      background-size: contain;
      background-repeat: no-repeat;
      background-position: center;
      border-radius: 10px;
      transition: transform 0.3s ease;

      &:hover {
        transform: scale(1.05);
      }

      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
      }
    }

    .man {
      background-image: url(../../images/man-bg.png);
    }

    .woman {
      background-image: url(../../images/woman-bg.png);
    }
  }
  .rate {
    display: flex;
    justify-content: space-evenly;
    color: white;
  }
  .charts {
    height: 50px;
  }
}
</style>
